$(function(){
	$("#email").blur(function(){
		let email = $(this).val();
		let myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		if(email==""){
			$("#emailver").html("请输入您的邮箱");
		}else if(!myreg.test(email))
		{
			$("#emailver").html("请输入正确的邮箱");
		}else if(myreg.test(email)){
			$.post("/emailExists/"+email,function(result){
				if(!result){//未被注册false，被注册true
					$("#emailver").html("你输入的邮箱还未被注册");
				}else{
					$("#emailver").html("");
				}
			});
		}else{
			$("#emailver").html("");
		}
	});
	$("#passwd").blur(function(){
		let passwd = $(this).val();
		if(passwd==""){
			$("#passwdver").html("请输入密码");
		} else if(passwd.length<8){
			$("#passwdver").html("请输入八位及以上字符作为密码");
		} else if(passwd.length>20){
			$("#passwdver").html("密码请不要超过20位");
		}else{
			$("#passwdver").html("");
		}
	});
	$("#verificationCode").blur(function(){
		let verificationCode = $(this).val();
		if(verificationCode==""){
			$("#verificationCodever").html("请输入验证码");
		}else if(verificationCode.length!=6){
			$("#verificationCodever").html("请输入完整的6位验证码");
		} else if(verificationCode.length==6){
			$("#verificationCodever").html("");
		}
	});
	$("#verificationCodeEmail").blur(function(){
		let verificationCodeEmail = $(this).val();
		if(verificationCodeEmail==""){
			$("#verificationCodeEmailver").html("请输入邮箱验证码");
		}else if(verificationCodeEmail.length!=8){
			$("#verificationCodeEmailver").html("请输入完整的8位验证码");
		} else if(verificationCodeEmail.length==8){
			$("#verificationCodeEmailver").html("");
		}
	});
});
$(document).keyup(function(event){
	let verificationCode = $("#verificationCode").val();
	if(verificationCode.length!=6&&$("#emailver").html()!=""){
		$("#submitverificationCode").attr("disabled",true);
	}else{
		$("#submitverificationCode").attr("disabled",false);
	}
});
$("#submitverificationCode").click(function(){
	let email = $("#email").val();
	if(email==""){
		$("#emailver").html("请输入您的邮箱");
	}else{
		$.post("/verificationExists/"+$("#verificationCode").val()+"/"+email,function(result){
			if(result){//正确true，不正确false
				alert("邮件以发送至邮箱，请查收！")
			}else {
				alert("你输入的验证码有误！");
				$("#verificationCode").val("");
				$("#imgflush").attr("src","/login/code?r=+Math.random()");
			}
		});
	}
});
function CheckPost(){
	if($("#emailver").html()!=""||$("#passwdver").html()!=""||$("#verificationCodever").html()!=""||$("#verificationCodeEmailver").html()!=""){
		return false;
	}else{
		return true;
	}
}